<template>
  <el-form ref="formRef" :model="state.formData" label-width="100px">
    <div class="fieldset">
      <div class="legend">基本属性</div>
      <slot name="property-subprocess-type" :model="state.formData" field="type">
        <el-form-item label="任务类型">
          <el-input v-model="state.formData.type" :disabled="true"></el-input>
        </el-form-item>
      </slot>

      <slot name="property-subprocess-name" :model="state.formData" field="name">
        <el-form-item label="显示名称">
          <el-input v-model="state.formData.display_name"></el-input>
        </el-form-item>
      </slot>
    </div>

    <div class="fieldset">
      <div class="legend">流程设置</div>
      <slot
        name="property-subprocess-sub_process"
        :model="state.formData"
        field="sub_process"
      >
        <el-form-item label="唯一编码">
          <el-input v-model="state.formData.sub_process"></el-input>
        </el-form-item>
      </slot>

      <slot
        name="property-subprocess-version"
        :model="state.formData"
        field="version"
      >
        <el-form-item label="流程版本">
          <el-input-number
            v-model="state.formData.version"
            :min="0"
            :max="10"
            controls-position="right"
          />
        </el-form-item>
      </slot>
    </div>

    <div class="fieldset">
      <div class="legend">拦截设置</div>
       <slot
        name="property-subprocess-pre_iterceptors"
        :model="state.formData"
        field="pre_iterceptors"
      >
      <el-form-item label="前置拦截器">
        <el-input v-model="state.formData.pre_iterceptors"></el-input>
      </el-form-item>
      </slot>

       <slot
        name="property-subprocess-post_interceptors"
        :model="state.formData"
        field="post_interceptors"
      >
      <el-form-item label="后置拦截器">
        <el-input v-model="state.formData.post_interceptors"></el-input>
      </el-form-item>
      </slot>
    </div>
  </el-form>
</template>

<script lang="ts">
import { reactive, ref, watch, defineProps, onMounted, defineEmits } from "vue";
import { FlowFormModel } from "../types";
export default {
  name: "ingeniousSubprocess",
};
</script>

<script setup lang="ts">
const state = reactive({
  formData: {} as FlowFormModel,
});

const formRef = ref(null);

const props = defineProps<{
  modelValue: FlowFormModel;
}>();

const emits = defineEmits(["update:modelValue"]);

watch(
  () => state.formData,
  (n, o) => {
    emits("update:modelValue", Object.assign(props.modelValue, state.formData));
  },
  { deep: true }
);

onMounted(() => {
  Object.assign(state.formData, props.modelValue);
});
</script>
